package com.lagou.controller;

import com.lagou.pojo.MailDTO;
import com.lagou.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName MailController
 * @Description
 * @Author playboy
 * @Date 2021/6/25 5:08 下午
 * @Version 1.0
 **/
@RestController
@RequestMapping("/email")
@RefreshScope
public class EmailController {

	@Autowired
	private MailService mailService;

	@RequestMapping("/{email}/{code}")
	public boolean email(@PathVariable("email") String email, @PathVariable("code") String code) {
		boolean result = true;
		MailDTO mailDTO = new MailDTO();
		mailDTO.setText("验证码：" + code);
		mailDTO.setSubject("验证码");
		mailDTO.setTo(new String[]{email});
		try {
			mailService.sendSimpleMailMessage(mailDTO);
		} catch (Exception e) {
			e.printStackTrace();
			result = false;
		}
		return result;
	}

}
